'''
词频统计日志模块
'''
import logging
import os
import time 

class log:
    '''
    日志显示类
    '''
    FORMATTER = logging.Formatter("%(asctime)s - %(levelname)s: %(message)s")
    INFO = logging.INFO
    WARN = logging.WARN
    WARNNING = logging.WARNING
    ERROR = logging.ERROR

    def __init__(self, filename='log.log', level=INFO):
        self.logger = logging.getLogger(name=filename)
        self.logger.setLevel(level)
        log_path = os.getcwd() + '/logs/'

        if not os.path.exists(log_path):
            os.mkdir(log_path)

        logfilename = log_path + filename
        fileHander = logging.FileHandler(logfilename, mode='a')
        fileHander.setLevel(level)
        fileHander.setFormatter(log.FORMATTER)
        self.logger.addHandler(fileHander)

    def info(self, msg, *args, **kwargs):
        self.logger.info(msg, *args, **kwargs)

    def warning(self, msg, *args, **kwargs):
        self.logger.warning(msg, *args, **kwargs)

    def error(self, msg, *args, **kwargs):
        self.logger.error(msg, *args, **kwargs)

    def debug(self, msg, *args, **kwargs):
        self.logger.debug(msg, *args, **kwargs)

def main():
    logger = log('text.log', log.INFO)
    logger.info('my test msg {}'.format(__name__))
    logger.warning('my test msg')
    logger.debug('my test msg')
    logger.error('my test msg')

if __name__ == '__main__':
    main()